package ee.serge.client;

import java.util.Date;

import com.google.gwt.user.client.Cookies;

public class Session {

   private static final long COOKIE_TIMEOUT = 1000 * 60 * 1;
   private static final String COOKIE_NAME = "GWTCOOKIE";
   private static String sessionId;
   
   private Session () {};
   
   public static void setSession(String _sessionId) {
      Date expireDate = new Date(new Date().getTime() + COOKIE_TIMEOUT);
      sessionId = _sessionId;
      Cookies.setCookie(COOKIE_NAME, _sessionId, expireDate);
   }
   
   public static boolean checkSession(String _sessionId) {
      return _sessionId.equals(Cookies.getCookie(COOKIE_NAME)) || _sessionId.equals(sessionId);
   }
   
   public static void endSession() {
      Cookies.removeCookie(COOKIE_NAME);
   }
   
}
